import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
export default defineConfig({
  base: process.env.NODE_ENV === 'production' ? '/' : '/',
  plugins: [
    vue(),
    vueJsx(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
    extensions:['.mjs','.js','.ts','.jsx','.tsx','.json'], // 导入时想要省略的扩展名列表
  },
  preview:{
      host: '192.168.3.33',
      port: 4000,//端口号
      strictPort: false,
      open: true,//是否自动打开浏览器
      outDir: "previewDist",
      assetsDir: "static",
  },
  server: {
    port: 9000, // 端口
    host: '0.0.0.0', // 监听的IP地址
    proxy: {
      '/api': {
        target: 'http://localhost:8080',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  },
  // publicDir: "public",
  build: {
    outDir: "dist",
    assetsDir: "static",
    cssCodeSplit: true,
    assetsInlineLimit: 4096,
    sourcemap: false,
    emptyOutDir: true,
    chunkSizeWarningLimit: 500 //chunk 大小警告的限制
  },
  esbuild: {
    //清除全局的console.log和debug
    drop: process.env.NODE_ENV === 'production' ? ['console', 'debugger'] : [],
  },
})
